<template>
    <div id="a3"></div>
  </template>
  <script>
  import * as echarts from "echarts";
  import { http } from "@/api/request";
  export default {
    data() {
      return {};
    },
    methods: {},
    components: {},
    computed: {},
    watch: {},
    created() {},
    async mounted() {
      var {continentStatis}=await http()
      var date=[],statis=[],ya=[],qi=[],beimei=[],dayang=[],ouzhou=[]
      continentStatis.forEach(item=>{
        date.push(item.date);
        statis.push(item.statis)
      })
      for (var i in statis) {
          for (var j in statis[i]) {
            if(j=='亚洲'){
              ya.push(statis[i][j])
            }
           else if(j=='其他'){
              qi.push(statis[i][j])

            }
            else if(j=='北美洲'){
              beimei.push(statis[i][j])

            }
            else if(j=='大洋洲'){
              dayang.push(statis[i][j])

            }
             else if(j=='欧洲'){
              ouzhou.push(statis[i][j])

            }
          }
            
      }
      // console.log(ya,'亚洲');
      // console.log(qi,'其他');
      // console.log(beimei,'北美');
      var chartDom = document.getElementById("a3");
      var myChart = echarts.init(chartDom);
      window.onresize = function() {
      myChart.resize()
    }
      var option = {
        backgroundColor: "#01004C",
        title: {},
        tooltip: {
          trigger: "axis",
        },
        legend: {
          data: ["亚洲", "其他", "北美洲", "大洋洲","欧洲"],
          textStyle: {
            color: "#fff",
          },
        },
        toolbox: {
          show: true,
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            magicType: { show: true, type: ["line", "bar"] },
            restore: { show: true },
            saveAsImage: { show: true },
          },
        },
        calculable: true,
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            data: date,
            axisLabel: {
              show: true,
              textStyle: {
                color: "#ebf8ac", //X轴文字颜色
                fontSize: 16,
              },
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            axisLabel: {
              formatter: "{value}",
              color: "#ccc",
              textStyle: {
                fontSize: 16,
              },
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: "#ccc",
              },
            },
          },
        ],
        series: [
          {
            name: "亚洲",
            type: "line",
            data: ya,
            lineStyle: {
              normal: {
                width: 2,
                color: {
                  type: "linear",
  
                  colorStops: [
                    {
                      offset: 0,
                      color: "#F7715D", // 0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: "#E3463B", // 100% 处的颜色
                    },
                  ],
                  globalCoord: false, // 缺省为 false
                },
                shadowColor: "rgba(72,216,191, 0.3)",
                shadowBlur: 6,
                shadowOffsetY: 10,
              },
            },
            itemStyle: {
              normal: {
                color: "#E3463B",
                borderWidth: 10,
                borderColor: "#ED8371",
              },
            },
            markPoint: {
              data: [{ name: "周最低", value: -2, xAxis: 1, yAxis: -1.5 }],
            },
          },
          {
            name: "其他",
            type: "line",
            data:qi,
            lineStyle: {
              normal: {
                width: 2,
                color: {
                  type: "linear",
  
                  colorStops: [
                    {
                      offset: 0,
                      color: "#D1DB40", // 0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: "#CED627", // 100% 处的颜色
                    },
                  ],
                  globalCoord: false, // 缺省为 false
                },
                shadowColor: "rgba(72,216,191, 0.3)",
                shadowBlur: 6,
                shadowOffsetY: 10,
              },
            },
            itemStyle: {
              normal: {
                color: "#CED627",
                borderWidth: 10,
                borderColor: "#EDFA67",
              },
            },
          },
          {
            name: "大洋洲",
            type: "line",
            lineStyle: {
              normal: {
                width: 2,
                color: {
                  type: "linear",
  
                  colorStops: [
                    {
                      offset: 0,
                      color: "#A9F387", // 0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: "#48D8BF", // 100% 处的颜色
                    },
                  ],
                  globalCoord: false, // 缺省为 false
                },
                shadowColor: "rgba(72,216,191, 0.3)",
                shadowBlur: 6,
                shadowOffsetY: 10,
              },
            },
            data: dayang,
            itemStyle: {
              normal: {
                color: "#48D8BF",
                borderWidth: 10,
                borderColor: "#A9F387",
              },
            },
            //smooth: true,
          },
          {
            name: "欧洲",
            type: "line",
            lineStyle: {
              normal: {
                width: 2,
                color: {
                  type: "linear",
  
                  colorStops: [
                    {
                      offset: 0,
                      color: "green", // 0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: "green", // 100% 处的颜色
                    },
                  ],
                  globalCoord: false, // 缺省为 false
                },
                shadowColor: "green",
                shadowBlur: 6,
                shadowOffsetY: 10,
              },
            },
            data: ouzhou,
            itemStyle: {
              normal: {
                color: "green",
                borderWidth: 10,
                borderColor: "green",
              },
            },
            //smooth: true,
          },
          {
            name: "欧洲",
            type: "line",
            lineStyle: {
              normal: {
                width: 2,
                color: {
                  type: "linear",
  
                  colorStops: [
                    {
                      offset: 0,
                      color: "yellow", // 0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: "yellow", // 100% 处的颜色
                    },
                  ],
                  globalCoord: false, // 缺省为 false
                },
                shadowColor: "yellow",
                shadowBlur: 6,
                shadowOffsetY: 10,
              },
            },
            data: beimei,
            itemStyle: {
              normal: {
                color: "yellow",
                borderWidth: 10,
                borderColor: "yellow",
              },
            },
            //smooth: true,
          },
        ],
      };
      option && myChart.setOption(option);
    },
  };
  </script>
  <style lang="scss" scoped>
  #a3 {
    width: 100%;
    height: 100%;
    padding: 10px;
    box-sizing: border-box;
  }
  </style>
  